import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React, { useEffect, useImperativeHandle, useRef, useState, } from "react";
import { Modal, message, Spin, Checkbox, Tooltip, } from "antd";
import notify from "devextreme/ui/notify";
import TreeView from "devextreme-react/tree-view";
import "./_style.less";
import { resetPidIfNotFound, MergeTypeConfig } from "../../tools/Tools";
import { extractFileInfo } from "../ExcelGrid/Tools";
import { getTemplateForNotesTreeList, menuTemplateExport, menuExportHaveTemplate, menuTemplateMerge, getCpasTableName, getAllVerifyTypeData, getNotesTreeZLToExportExcel, getLeftTreeList, getBaseDataApi, getCpatableToBatchExportExcel, } from "../ExcelGrid/api/DesignTableApi";
import { trialNameSort, unFinancialNameSort } from "./utils";
const { confirm } = Modal;
const CpasModal = React.forwardRef((props, ref) => {
    const { type, okCallback, cancelCallback, beforeCallback, dataId, zcbfid, dsTableRef, zcbfName, exportSort, onlyProjectName, } = props;
    // const [tableData, setTableData] = useState<any[]>([]);
    const [exportModalShow, setExportModalShow] = useState(false);
    const [importType, setImportType] = useState("db"); //导入类型；默认：default 导入db, template 模版导入
    const [importParam, setImportParam] = useState({});
    const [modalType, setModalType] = useState("default"); // default: 默认 导出db, import： 导入db, exportZLExcel: 导出整理后excel, exportExcel: 导出excel整理前
    const treeViewRef = useRef(null);
    const [checkedTitles, setCheckedTitles] = useState([]);
    const [checkedNotesId, setCheckedNotesId] = useState([]);
    const [getImportTreesData, setImportTreesData] = useState([]);
    const [noteTitle, setNoteTitle] = useState("");
    const [noteLists, setNoteLists] = useState([]);
    const [btnLoading, setBtnLoading] = useState(false);
    const [isModalLoading, setIsModalLoading] = useState(false);
    const [isExportClear, setIsExportClear] = useState(false);
    const [isRightTemplateAdd, setIsRightTemplateAdd] = useState(false); //是否是右键模版库添加
    // 自定义方法
    useImperativeHandle(ref, () => ({
        openExportAllDialog: async (params) => {
            // const isClear = isClearData ? isClearData : false;
            // const isExport = isExportUnFinancial ? isExportUnFinancial : false;
            await openExportAllDialog(params);
        },
        /**
         * 导出附注全部
         */
        openExportAllNotesDialog: async (modalName, isClearData) => {
            console.log(modalName, "modalName-----");
            setModalType(modalName);
            MODAL_CONFIRM_FN["exportZLExcel"](modalName, true, isClearData);
        },
        /**
         * 导出全部财务报表
         */
        openExportFinanceReportDialog: async (tname, isClearData, successCallback) => {
            await openExportFinanceReportDialog(tname, isClearData);
            successCallback && successCallback();
        },
        //打开导入db弹框
        openImportDBDialog: async (successCallback) => {
            await openImportDBDialog();
            successCallback && successCallback();
        },
        //导出db弹框
        openExportDBDialog: async () => {
            setExportModalShow(true);
            setCheckedTitles([]);
            setCheckedNotesId([]);
            setModalType("default");
            await initReload();
            // await getListsTree()
        },
        //导出excel弹窗
        openExportExcelDialog: async (modalName) => {
            console.log(modalName, "modalName---type", type);
            setExportModalShow(true);
            setCheckedTitles([]);
            setCheckedNotesId([]);
            setModalType(modalName);
            setIsExportClear(false);
            setImportTreesData([]);
            await initReload();
            // await getListsTree()
            treeViewRef?.current?.instance.selectAll();
        },
        //右键模版库功能成功回调
        /**
         *
         * @param modalName
         * @param data
         * @param curNodeRef
         * @param successCallback
         * @returns
         */
        confrimRightTemplateCallback: async (data, curNodeRef, successCallback) => {
            console.log(curNodeRef?.current?.title, "curNodeRef.current-----");
            const titles = [data];
            setCheckedTitles(titles);
            setIsRightTemplateAdd(true);
            setImportType("template");
            try {
                const res = await getTemplateForNotesTreeList({
                    templateName: data,
                });
                const treeList = res && res.data ? res.data : null;
                if (treeList && treeList.length) {
                    const resetData = resetPidIfNotFound(treeList);
                    setModalType("import");
                    const dataTree = resetData.map((item) => {
                        // if (item.isAlwaysShow) {
                        // defaultCheckedKey.push(item.id)
                        // setDefaultCheckedKey([...defaultCheckedKey])
                        // }
                        const oldTree = noteLists.filter((oldItem) => oldItem.fid === item.fid);
                        let isExpanded = false;
                        if (localStorage.getItem("isExpanded") === "true" ||
                            (oldTree && oldTree[0]?.expanded)) {
                            isExpanded = true;
                        }
                        const obj = {
                            icon: "icon-biaogeyangshiku",
                            parentId: item.pid,
                            expanded: isExpanded,
                            key: item.title,
                            isDirectory: true,
                            ...item,
                        };
                        return obj;
                    });
                    setImportTreesData(dataTree);
                    setExportModalShow(true);
                    const param = {
                        // dbName: dbname,
                        templateName: data,
                        type: "ds",
                        dataId: dataId,
                        opt: {
                            duplicate: "copy",
                            targetId: curNodeRef?.current?.fid,
                            targetPlace: "down",
                        },
                    };
                    setImportParam(param);
                    successCallback && successCallback();
                    setIsRightTemplateAdd(false);
                    // initReload(curNodeRef?.current?.title, "switchTemplate");
                }
                else {
                    return notify("导入节点为空", "error", 2000);
                }
            }
            catch (e) {
                return notify("导入节点加载失败", "error", 2000);
            }
        },
    }));
    useEffect(() => {
        console.log("modal useEffect");
        if (dataId) {
            initReload();
        }
    }, [dataId]);
    const initReload = async () => {
        const resData = await getLeftTreeList(dataId);
        if (resData && resData.length) {
            const dataTreee = resetPidIfNotFound(resData);
            setNoteLists(dataTreee);
        }
    };
    const executeFSExport = async (tname, dirName, fileName, isClearData) => {
        props.beforeCallback && props.beforeCallback();
        props.progressCallback && props.progressCallback(30);
        const resData = await getBaseDataApi("account.getFSTableNames", {
            tableType: tname,
        });
        props.progressCallback && props.progressCallback(60);
        console.log(resData, "resData-----", exportSort);
        if (resData && resData.length) {
            let sortData = resData;
            //按照页面展示的页签进行排序
            if (tname === "试算平衡") {
                const periodSetting = window?.sessionStorage?.periodSetting
                    ? JSON.parse(window.sessionStorage.periodSetting)
                    : null;
                if (periodSetting && periodSetting.length) {
                    sortData = resData.filter((itemA) => periodSetting.some((itemB) => itemA.name.includes(itemB?.Data_ID)));
                }
                sortData = trialNameSort(sortData);
            }
            else if (tname === "未审财务") {
                sortData = unFinancialNameSort(resData);
            }
            const excelInfo = [];
            for (let i = 0; i < sortData.length; i++) {
                const { name } = sortData[i];
                let number = 0;
                excelInfo.push({
                    cpastableParam: {
                        tempTname: name,
                        tname: name,
                        type: "fs",
                    },
                    number: number ? number : i,
                    exportType: "primary",
                    excelSheetName: name,
                    isBatchExport: true,
                    isExportTableTitle: true,
                    signDirection: "vertical",
                    tableDate: " ",
                    // tableLfDesc: "编制单位： 三元集团123",
                    // tableRiDesc: "单位：人民币元",
                    tableTitle: name,
                });
            }
            excelInfo.sort((a, b) => a.number - b.number);
            console.log(excelInfo, "excelInfo----");
            props.progressCallback && props.progressCallback(90);
            try {
                let defaultFilteName = tname;
                if (tname === "试算平衡") {
                    defaultFilteName = "试算平衡表";
                }
                if (tname === "未审财务") {
                    defaultFilteName = "未审财务报表";
                }
                if (onlyProjectName) {
                    defaultFilteName = `${onlyProjectName}-${defaultFilteName}`;
                }
                const res = await getCpatableToBatchExportExcel({
                    directoryPath: dirName,
                    excelFileName: fileName ? fileName : defaultFilteName,
                    excelInfo,
                    isClearData,
                });
                props.progressCallback && props.progressCallback(100);
                if (res.ok) {
                    props.okCallback && props.okCallback();
                    const okName = tname ? `${tname}导出成功~` : "导出成功~";
                    return message.success(okName);
                }
                else {
                    props.errorCallback && props.errorCallback(res);
                    return message.error(res.msg || "导出失败");
                }
            }
            catch (e) {
                props.errorCallback && props.errorCallback(e);
                return message.error("导出失败");
            }
        }
        else {
            props.cancelCallback && props.cancelCallback();
        }
    };
    const executeDsExport = async (isNotes, dirName, fileName, allNotesId, isClearData) => {
        props.beforeCallback && props.beforeCallback();
        props.progressCallback && props.progressCallback(30);
        setIsModalLoading(true);
        try {
            props.progressCallback && props.progressCallback(60);
            const res = await getNotesTreeZLToExportExcel({
                partId: zcbfid,
                dataId,
                type: "ds",
                // directoryPath: "./Temp",
                directoryPath: dirName,
                excelFileName: fileName,
                nodes: allNotesId,
                // nodes: result,
                exportType: "primary",
                isClearData: isClearData,
                isToZl: !isNotes,
            });
            props.progressCallback && props.progressCallback(90);
            setBtnLoading(false);
            setIsModalLoading(false);
            props.okCallback && props.okCallback();
            if (res.ok) {
                props.okCallback && props.okCallback();
                message.success("附注导出成功~");
                setExportModalShow(false);
            }
            else {
                props.cancelCallback && props.cancelCallback();
                message.error(res.msg || "导出失败");
            }
        }
        catch (error) {
            props.errorCallback && props.errorCallback(error);
        }
        return;
    };
    const openExportAllDialog = async (params) => {
        let electronComponents;
        if (window.parent) {
            electronComponents = window["parent"]["electronComponents"];
        }
        else {
            electronComponents = window["electronComponents"];
        }
        const { isClearData = false, mergeSystemType = "" } = params;
        const excelName = "";
        const dialog_result = await electronComponents.openDirectoryDialog("保存");
        const checkFolderPath = dialog_result?.filePaths;
        if (checkFolderPath && checkFolderPath.length && !dialog_result.canceled) {
            const dirName = checkFolderPath[0];
            if (mergeSystemType && mergeSystemType === MergeTypeConfig.HB_FD) {
                await executeFSExport("未审财务", dirName, "", isClearData);
            }
            await executeFSExport("试算平衡", dirName, "", isClearData);
            let allNotesId;
            const resData = await getLeftTreeList(dataId);
            if (resData && resData.length) {
                const dataTreee = resetPidIfNotFound(resData);
                allNotesId = dataTreee.slice();
            }
            if (allNotesId) {
                // const defaultZlName = onlyProjectName
                //   ? `${onlyProjectName}-Excel附注.xlsx`
                //   : "Excel附注.xlsx";
                const defaultName = onlyProjectName
                    ? `${onlyProjectName}-Excel附注模版`
                    : "Excel附注模版";
                await executeDsExport(true, dirName, defaultName, allNotesId, isClearData);
                // await executeDsExport(
                //   true,
                //   dirName,
                //   defaultZlName,
                //   allNotesId,
                //   isClearData
                // );
            }
        }
    };
    /**
     * 导出全部试算平衡表
     */
    const openExportFinanceReportDialog = async (tname, isClearData) => {
        let defaultFilteName = tname;
        if (tname === "试算平衡") {
            defaultFilteName = "试算平衡表";
        }
        if (tname === "未审财务") {
            defaultFilteName = "未审财务报表";
        }
        if (onlyProjectName) {
            defaultFilteName = `${onlyProjectName}-${defaultFilteName}`;
        }
        let electronComponents;
        if (window.parent) {
            electronComponents = window["parent"]["electronComponents"];
        }
        else {
            electronComponents = window["electronComponents"];
        }
        const excelName = defaultFilteName;
        try {
            const dialog_result = await electronComponents.showSaveDialog("xlsx", excelName);
            const checkFolderPath = dialog_result?.filePath;
            if (checkFolderPath && !dialog_result.canceled) {
                const { dirName, fileName } = extractFileInfo(checkFolderPath);
                // 开始导出
                props.progressCallback && props.progressCallback(0);
                executeFSExport(tname, dirName, fileName, isClearData);
            }
            else {
                props.cancelCallback && props.cancelCallback();
            }
        }
        catch (error) {
            props.errorCallback && props.errorCallback(error);
        }
    };
    /**
     * 附注导入db
     * @returns
     */
    const openImportDBDialog = async () => {
        let electronComponents;
        if (window.parent) {
            electronComponents = window["parent"]["electronComponents"];
        }
        else {
            electronComponents = window["electronComponents"];
        }
        // setIsRightTemplateAdd(false);
        const dialog_result = await electronComponents.openFileDialog("db");
        const checkFolderPath = dialog_result && dialog_result?.filePaths.length
            ? dialog_result?.filePaths[0]
            : null;
        console.log(dialog_result, "dialog_result");
        if (checkFolderPath) {
            console.log(checkFolderPath, "checkFolderPath");
            setImportType("db");
            try {
                const res = await getTemplateForNotesTreeList({
                    templateFile: checkFolderPath,
                });
                const treeList = res && res.data ? res.data : null;
                if (treeList && treeList.length) {
                    const resetData = resetPidIfNotFound(treeList);
                    setModalType("import");
                    const dataTree = resetData.map((item) => {
                        // if (item.isAlwaysShow) {
                        //   defaultCheckedKey.push(item.id)
                        //   setDefaultCheckedKey([...defaultCheckedKey])
                        // }
                        const oldTree = noteLists.filter((oldItem) => oldItem.fid === item.fid);
                        let isExpanded = false;
                        if (localStorage.getItem("isExpanded") === "true" ||
                            (oldTree && oldTree[0]?.expanded)) {
                            isExpanded = true;
                        }
                        const obj = {
                            icon: "icon-biaogeyangshiku",
                            parentId: item.pid,
                            expanded: isExpanded,
                            key: item.title,
                            isDirectory: true,
                            ...item,
                        };
                        return obj;
                    });
                    setImportTreesData(dataTree);
                    setExportModalShow(true);
                    const param = {
                        templateFile: checkFolderPath,
                        type: "ds",
                        dataId: treeList && treeList.length ? treeList[0].Data_ID : dataId,
                        opt: {
                            duplicate: "cover",
                        },
                    };
                    setImportParam(param);
                }
                else {
                    return notify("导入节点为空", "error", 2000);
                }
            }
            catch (e) {
                notify("导入节点加载失败", "error", 2000);
                throw e;
            }
        }
    };
    /**
     * 导出db
     */
    async function templateExportDB(checkFolderPath) {
        // setShowTemplateOpen(true)
        const selectedEmployees = treeViewRef?.current?.instance
            .getSelectedNodes()
            .map((node) => node.itemData);
        let allNotesTitle = selectedEmployees.map((item) => item.title);
        props.loadingCallback && props.loadingCallback(true);
        const params = {
            templateFile: checkFolderPath,
            tableNames: allNotesTitle,
            type: "ds",
            dataId: dataId,
        };
        const resData = await menuTemplateExport(params);
        if (resData.code === 200) {
            setExportModalShow(false);
            // setShowTemplateOpen(false)
            props.loadingCallback && props.loadingCallback(false);
            setCheckedTitles([]);
            setCheckedNotesId([]);
            treeViewRef?.current?.instance?.unselectAll();
            return notify("导出成功~", "success", 2000);
        }
        else {
            // setShowTemplateOpen(false)
            props.loadingCallback && props.loadingCallback(false);
            return notify(resData.msg, "error", 2000);
        }
    }
    const exportDB = async (checkFolderPath) => {
        const haveParams = {
            //filePath: `${checkFolderPath[0]}\\${exportName}`
            filePath: checkFolderPath,
        };
        const res = await menuExportHaveTemplate(haveParams);
        if (res.data) {
            return confirm({
                title: "提示",
                content: "当前文件已存在，是否覆盖该文件？",
                async onOk() {
                    templateExportDB(checkFolderPath);
                },
                onCancel() {
                    console.log("Cancel");
                },
            });
        }
        else {
            templateExportDB(checkFolderPath);
        }
    };
    //modal 导出导入的确认动作
    const MODAL_CONFIRM_FN = {
        /**
         * 导出db确认
         */
        default: async () => {
            console.log(checkedTitles, "checkedTitles");
            const selectedEmployees = treeViewRef?.current?.instance
                ? treeViewRef?.current?.instance
                    .getSelectedNodes()
                    .map((node) => node.itemData)
                : checkedTitles;
            let allNotesTitle = selectedEmployees.map((item) => item.title);
            //if (!exportName || checkedTitles.length === 0) {
            if (!allNotesTitle.length || allNotesTitle.length === 0) {
                return notify("导出模板名称/项目表为空！", "error", 2000);
            }
            else {
                let electronComponents;
                if (window.parent) {
                    electronComponents = window["parent"]["electronComponents"];
                }
                else {
                    electronComponents = window["electronComponents"];
                }
                setBtnLoading(true);
                const dialog_result = await electronComponents.showSaveDialog("db", `附注_${zcbfName}.db`);
                console.log(dialog_result, "dialog_result 结果展示");
                const checkFolderPath = dialog_result.filePath;
                setBtnLoading(false);
                if (checkFolderPath && checkFolderPath.length > 0) {
                    return exportDB(checkFolderPath);
                }
            }
        },
        /**
         * 导入db确认
         */
        import: async () => {
            const importDataId = getImportTreesData &&
                getImportTreesData.length &&
                getImportTreesData[0].Data_ID
                ? getImportTreesData[0].Data_ID
                : dataId;
            console.log(importDataId, "importDataId 导入年度对比", dataId);
            const selectedEmployees = treeViewRef?.current?.instance
                ? treeViewRef?.current?.instance
                    .getSelectedNodes()
                    .map((node) => node.itemData)
                : checkedTitles;
            let allNotesTitle = selectedEmployees.map((item) => item.title);
            if (!allNotesTitle.length || allNotesTitle.length === 0) {
                return notify("导入模板名称为空！", "error", 2000);
            }
            if (importType === "db" && importDataId !== dataId) {
                setExportModalShow(false);
                return notify("导入的DB年度与当前年度不符，请重新选择！", "error", 4000);
            }
            const params = {
                ...importParam,
                tableNames: allNotesTitle,
            };
            setBtnLoading(true);
            // setShowTemplateOpen(true);
            props.loadingCallback && props.loadingCallback(true);
            if (Object.keys(params).length > 0) {
                try {
                    const mergeData = await menuTemplateMerge(params);
                    console.log("合并结果", mergeData);
                    if (mergeData.ok) {
                        setExportModalShow(false);
                        setImportTreesData([]);
                        const tname = Array.isArray(allNotesTitle)
                            ? allNotesTitle.join("||")
                            : allNotesTitle;
                        const params = {
                            // dbname: dbname,
                            tname: tname,
                            data_id: dataId,
                            type: "ds",
                            is_array: true,
                        };
                        const res = await getCpasTableName(params);
                        if (res?.ok && res?.data) {
                            const cpastableData = res.data;
                            const tids = [];
                            for (let i = 0; i < cpastableData.length; i++) {
                                tids.push(cpastableData[i].tid);
                            }
                            console.log(tids, "cpastab表查询tids");
                            // await reCalculateNotesAPI({
                            //   dbname,
                            //   data_id: getDataIds,
                            //   tids,
                            // });
                            //@todo-dingxiaofei12月22日记录，经和小平,测试,莎莎沟通，右键模版库暂不执行钩稽重算，因为右键模库导入操作找不到tid
                            if (!isRightTemplateAdd) {
                                await getAllVerifyTypeData({
                                    data_id: dataId,
                                    tids,
                                    // is_stop_rec: true,
                                    type: "vr",
                                });
                            }
                        }
                        setBtnLoading(false);
                        // setShowTemplateOpen(false);
                        props.loadingCallback && props.loadingCallback(false);
                        notify("导入成功", "success", 2000);
                        if (dsTableRef && +dsTableRef?.current?.state?.tabValue === 2) {
                            dsTableRef.current.tabModelChanges("1");
                        }
                        props.importOkCallback && (await props.importOkCallback()); //刷新附注;
                    }
                    else {
                        // setShowTemplateOpen(false)
                        props.loadingCallback && props.loadingCallback(false);
                        setBtnLoading(false);
                        notify(mergeData.msg, "error", 2000);
                    }
                }
                catch (e) {
                    // setShowTemplateOpen(false)
                    props.loadingCallback && props.loadingCallback(false);
                    setBtnLoading(false);
                    notify("导入失败", "error", 2000);
                    throw e;
                }
            }
        },
        /**
         * 附注导出成果
         */
        exportZLExcel: async (modalName, isExportAll, isClearData) => {
            console.log("exportZlExcel-----");
            props.beforeCallback && props.beforeCallback();
            // let allNotesId = checkedNotesId;
            const selectedEmployees = treeViewRef?.current?.instance
                ? treeViewRef?.current?.instance
                    .getSelectedNodes()
                    .map((node) => node.itemData)
                : checkedNotesId;
            let allNotesId = selectedEmployees.map((item) => {
                return {
                    id: item.fid,
                    fid: item.fid,
                    pid: item.pid,
                    parentId: item.pid,
                    name: item.title,
                    orderNo: item.orderNo,
                };
            });
            try {
                if (isExportAll) {
                    const resData = await getLeftTreeList(dataId);
                    if (resData && resData.length) {
                        const dataTreee = resetPidIfNotFound(resData);
                        allNotesId = dataTreee;
                    }
                }
            }
            catch (error) {
                props.errorCallback && props.errorCallback(error);
                return;
            }
            if (!allNotesId.length || allNotesId.length === 0) {
                props.errorCallback && props.errorCallback("");
                return notify("导出节点为空！", "error", 2000);
            }
            let electronComponents;
            if (window.parent) {
                electronComponents = window["parent"]["electronComponents"];
            }
            else {
                electronComponents = window["electronComponents"];
            }
            //const dialog_result = await electronComponents.openDirectoryDialog();
            setBtnLoading(true);
            let excelName = onlyProjectName
                ? `${onlyProjectName}-Excel附注.xlsx`
                : "Excel附注.xlsx";
            const isNotes = modalType === "exportExcel" ||
                (modalName && modalName === "exportExcel"); //是否是附注
            if (isNotes) {
                excelName = onlyProjectName
                    ? `${onlyProjectName}-Excel附注模版.xlsx`
                    : "Excel附注模版.xlsx";
            }
            const dialog_result = await electronComponents.showSaveDialog("xlsx", excelName);
            console.log(dialog_result, "dialog_result 结果展示");
            const checkFolderPath = dialog_result?.filePath;
            console.log(checkFolderPath, "checkFolderPath----");
            if (checkFolderPath && !dialog_result.canceled) {
                // 开始导出
                props.progressCallback && props.progressCallback(0);
                const { dirName, fileName } = extractFileInfo(checkFolderPath);
                const isClear = isClearData ? isClearData : isExportClear;
                const newDirName = dirName || checkFolderPath;
                await executeDsExport(isNotes, newDirName, fileName, allNotesId, isClear);
            }
            else {
                setBtnLoading(false);
                props.cancelCallback && props.cancelCallback();
                return message.warning("取消了选择路径~");
            }
        },
        /**
         * 附注导出成果
         */
        exportZLExcelTodraft: async (modalName, isExportAll, isClearData) => {
            // let allNotesId = checkedNotesId;
            const selectedEmployees = treeViewRef?.current?.instance
                ? treeViewRef?.current?.instance
                    .getSelectedNodes()
                    .map((node) => node.itemData)
                : checkedNotesId;
            let allNotesId = selectedEmployees.map((item) => {
                return {
                    id: item.fid,
                    fid: item.fid,
                    pid: item.pid,
                    parentId: item.pid,
                    name: item.title,
                    orderNo: item.orderNo,
                };
            });
            if (isExportAll) {
                const resData = await getLeftTreeList(dataId);
                if (resData && resData.length) {
                    const dataTreee = resetPidIfNotFound(resData);
                    allNotesId = dataTreee;
                }
            }
            if (!allNotesId.length || allNotesId.length === 0) {
                return notify("导出节点为空！", "error", 2000);
            }
            setBtnLoading(true);
            const isClear = isClearData ? isClearData : isExportClear;
            // const newDirName = dirName || checkFolderPath;
            await executeDsExport(false, "./Temp", "Excel附注", allNotesId, isClear);
            // 执行 选择底稿弹窗
            props.okCallback && props.okCallback();
        },
    };
    const treeViewSelectionChanged = (e) => {
        const treeView = e.component;
        if (treeView) {
            const selectedEmployees = treeView
                .getSelectedNodes()
                .map((node) => node.itemData);
            console.log(selectedEmployees, "selectedEmployees 已勾选节点");
            const allTitles = selectedEmployees.map((item) => item.title);
            const allIds = selectedEmployees.map((item) => {
                return {
                    id: item.fid,
                    fid: item.fid,
                    pid: item.pid,
                    parentId: item.pid,
                    name: item.title,
                    orderNo: item.orderNo,
                };
            });
            //const allTids: any = selectedEmployees.map((item: any) => item.id);
            setCheckedTitles(allTitles);
            setCheckedNotesId(allIds);
            //setCheckedNotesTids(allTids);
        }
    };
    const exportModalItemTemplate = (m) => {
        return (_jsx(React.Fragment, { children: _jsx(Tooltip, { title: m.title, placement: "rightTop", children: m.title }) }));
    };
    const onCheckboxCleaChange = (e) => {
        const checked = e.target.checked;
        setIsExportClear(checked);
    };
    const renderClearCpasTable = () => {
        if (modalType === "exportExcel") {
            return (_jsx("div", { className: "export-clear", children: _jsx(Checkbox, { checked: isExportClear, onChange: onCheckboxCleaChange, children: "\u662F\u5426\u6E05\u7A7A\u6570\u636E" }) }));
        }
    };
    const importDataId = getImportTreesData &&
        getImportTreesData.length &&
        getImportTreesData[0].Data_ID
        ? getImportTreesData[0].Data_ID
        : "";
    return (_jsx(Modal, { open: exportModalShow, title: modalType === "import" ? "导入" : "导出", maskClosable: false, destroyOnClose: true, width: 600, onCancel: () => {
            if (isModalLoading) {
                return notify("正在导出，请勿取消~", "warning", 2000);
            }
            setExportModalShow(false);
            setIsRightTemplateAdd(false);
            setImportTreesData([]);
            setImportParam({});
            props.cancelCallback && props.cancelCallback();
        }, onOk: () => modalType === "exportExcel"
            ? MODAL_CONFIRM_FN["exportZLExcel"]()
            : MODAL_CONFIRM_FN[modalType](), confirmLoading: btnLoading, children: _jsx(Spin, { spinning: isModalLoading, delay: 500, tip: "\u00A0\u00A0\u6570\u636E\u5BFC\u51FA\u4E2D\uFF5E", children: _jsxs("div", { className: "pro-list export-pro-list", children: [_jsx("div", { className: "export-name" }), _jsx("div", { style: { paddingBottom: importDataId ? 20 : 0 }, children: importDataId ? `导入年度: ${importDataId}` : "" }), renderClearCpasTable(), _jsx(TreeView, { id: "treeview", width: "100%", height: "100%", dataStructure: "plain", ref: treeViewRef, items: getImportTreesData && getImportTreesData.length
                            ? getImportTreesData
                            : noteLists, 
                        //expandedExpr="expanded"
                        displayExpr: "title", parentIdExpr: "pid", keyExpr: "id", selectByClick: true, selectNodesRecursive: false, selectAllText: "\u5168\u9009", showCheckBoxesMode: "selectAll", selectionMode: "multiple", searchEnabled: true, itemRender: exportModalItemTemplate, 
                        //value={checkedTitles}
                        onSelectionChanged: treeViewSelectionChanged })] }) }) }));
});
export default CpasModal;
